package com.jddup.program.comparator;

import com.jddup.common.pojo.EntityAndDbDifference;
import com.jddup.common.pojo.TableMeta;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
 * Created by ZZB on 2017/12/4.
 */
public interface EntityAndDbComparator {
    Logger logger = LoggerFactory.getLogger(EntityAndDbComparator.class);

    EntityAndDbDifference comparator(TableMeta entity, TableMeta db);

    default void putIntoDifference(EntityAndDbDifference difference, String columnName,String message, EntityAndDbDifference.ModifyDDL.LevelEnums level, String... sql) {
        List<String> sqls = Arrays.asList(sql);
        difference.getDiffMap().put(columnName, new EntityAndDbDifference.ModifyDDL(level, sqls,message));
        String msg = message +"\n"+ sqls.stream().reduce((s, s2) -> "["+s + "]["+ s2 +"]").orElse("[]");
        if(level.equals(EntityAndDbDifference.ModifyDDL.LevelEnums.serious)){
            logger.error(msg);
        } else {
            logger.warn(msg);
        }
    }
}
